package com.wxzz.elearing.comment.api.admin;


import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.comment.dto.ApplyStudyTitleTypeDto;
import com.wxzz.elearing.comment.entity.ApplyStudyTitleType;
import com.wxzz.elearing.comment.entity.SkillCenterCategory;
import com.wxzz.elearing.comment.service.IApplyStudyTitleTypeService;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2021-05-18
 */
@RestController
@RequestMapping("/apply-study-title-type")
@Api(tags = "学以致用标题类型(企业)")
public class ApplyStudyTitleTypeController {

    @Autowired
    private IApplyStudyTitleTypeService iApplyStudyTitleTypeService;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @ApiOperation(value = "添加学以致用标题类型(企业)", notes = "添加学以致用标题类型(企业)", httpMethod = "POST", tags = "企业")
    @RequestMapping(value = "saveApplyType", method = RequestMethod.POST)
    public ReturnVO saveApplyType(@RequestBody ApplyStudyTitleType applyStudyTitleType, @RequestHeader(value = "token") String token) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        applyStudyTitleType.setEnterpriseId(jsonObject.getLong("enterpriseId"));
        return iApplyStudyTitleTypeService.saveApplyType(applyStudyTitleType);
    }

    @ApiOperation(value = "学以致用标题类型列表(企业)", notes = "添加学以致用标题类型列表(企业)", httpMethod = "POST", tags = "企业")
    @RequestMapping(value = "applyTypeList", method = RequestMethod.POST)
    public ReturnVO applyTypeList(@RequestBody ApplyStudyTitleTypeDto applyStudyTitleType, @RequestHeader(value = "token") String token) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        applyStudyTitleType.setEnterpriseId(jsonObject.getLong("enterpriseId"));
        return iApplyStudyTitleTypeService.applyTypeList(applyStudyTitleType);
    }

    @ApiOperation(value = "删除学以致用标题类型(企业)", notes = "删除学以致用标题类型(企业)", httpMethod = "POST", tags = "企业")
    @RequestMapping(value = "deleteApplyType", method = RequestMethod.POST)
    public ReturnVO deleteApplyType(@RequestBody ApplyStudyTitleType applyStudyTitleType) {
        return iApplyStudyTitleTypeService.deleteApplyType(applyStudyTitleType);
    }
}
